[PB-6472]: feat/track-user-mail-usage#220
Conversation
|
The This makes the network less coupled to mail/drive/any product we may release in the future that consumes space while gaining standarisation of the calculus of the used space on a bucket. WDYT @apsantiso @jzunigax2 ? This may be even useful for Photos or the same Drive in any foreseeable future. |
Add a usedSpaceBytes field to buckets and a gateway endpoint to set it, so products whose content lives outside the network (mail/Stalwart) can report the space they consume against a network bucket.
02b5882 to
6f17e6b
Compare
Add a new method to sum used space bytes in MongoDBBucketsRepository and update the UsersUsecase to return a UserSpaceSnapshot when setting bucket usage. Update HTTPGatewayController to send the snapshot in the response. Include tests to verify the new functionality.
|
|
||
| return { | ||
| maxSpaceBytes: user.maxSpaceBytes, | ||
| totalUsedSpaceBytes: user.totalUsedSpaceBytes + bucketsUsedSpaceBytes, |
There was a problem hiding this comment.
why? The user's totalUsedSpaceBytes already includes the bucketsUsedSpaceBytes
There was a problem hiding this comment.
that's the main issue here. The network needs to know how much space is consumed by mail. However mail blobs (bodies and attachments) are managed and stored by stalwart that upload path does not come through the network. I though about leveraging sieve scripts, event hooks or similar to also store the metadata on here, though that would create the problem of mantaining both
as it stands mail just reports the its usage which would not be part of totalUsedSpaceBytes as its contents did not go through the normal upload flow
| } | ||
| } | ||
|
|
||
| async setBucketUsage( |
There was a problem hiding this comment.
I do not know if it fits you but, isn't it better to set this on any upload so when you use the upload endpoint for mail, the computation for that bucket is set?
What
Adds a
usedSpaceBytesfield to buckets and a gateway endpoint for setting it:PUT /v2/gateway/users/:uuid/buckets/:id/usageMail provisions one bucket per mail account #221 and periodically reports that account's usage from Stalwart here.
Why
Bridge needs to track each user's mail storage usage next to their Drive usage so the two can be checked against a single quota. Per review feedback: the bucket is the right entity to carry used space. Per review feedback: the bucket is the right entity to carry used space
How
usedSpaceBytesadded to the bucket domain type and mongoose schema (default 0).BucketsRepository.setUsedSpaceBytes(bucketId, userId, value): a single atomicupdateOnefiltered on_id+ owner uuid; reports whether a document matched.UsersUsecase.setBucketUsage: throwsBucketNotFoundErrorwhen nothing matchedusedSpaceBytesis a non-negative finite number; JWT-protected like the rest of the gateway.